From 5840748740cdcc8db0d92ef81c893afec159270d Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Thu, 24 Nov 2005 15:57:36 +0000 Subject: [PATCH] Check whether a device is already configured before trying to configure it again. Closes bug #397. To perform this check in the same transaction as the writing of the device entries has required a little bit of rejigging. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/server/DevController.py | 74 ++++++++++++------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/tools/python/xen/xend/server/DevController.py b/tools/python/xen/xend/server/DevController.py index 4bb8642226..6f19dccf1b 100644 --- a/tools/python/xen/xend/server/DevController.py +++ b/tools/python/xen/xend/server/DevController.py @@ -79,9 +79,36 @@ class DevController: if devid is None: return 0 - self.writeDetails(config, devid, back, front) + (backpath, frontpath) = self.addStoreEntries(config, devid, back, + front) - return devid + while True: + t = xstransact() + try: + if devid in self.deviceIDs(t): + if 'dev' in back: + dev_str = '%s (%d, %s)' % (back['dev'], devid, + self.deviceClass) + else: + dev_str = '%s (%s)' % (devid, self.deviceClass) + + raise VmError("Device %s is already connected." % dev_str) + + log.debug('DevController: writing %s to %s.', str(front), + frontpath) + log.debug('DevController: writing %s to %s.', str(back), + backpath) + + t.remove2(backpath, HOTPLUG_STATUS_NODE) + + t.write2(frontpath, front) + t.write2(backpath, back) + + if t.commit(): + return devid + except: + t.abort() + raise def waitForDevices(self): @@ -245,21 +272,29 @@ class DevController: raise VmError("Device %s not connected" % devid) - def deviceIDs(self): + def deviceIDs(self, transaction = None): """@return The IDs of each of the devices currently configured for this instance's deviceClass. """ - return map(int, xstransact.List(self.frontendRoot())) + fe = self.frontendRoot() + if transaction: + return map(lambda x: int(x.split('/')[-1]), transaction.list(fe)) + else: + return map(int, xstransact.List(fe)) ## private: - def writeDetails(self, config, devid, backDetails, frontDetails): - """Write the details in the store to trigger creation of a device. - The backend domain ID is taken from the given config, paths for - frontend and backend are computed, and these are written to the store - appropriately, including references from frontend to backend and vice - versa. + def addStoreEntries(self, config, devid, backDetails, frontDetails): + """Add to backDetails and frontDetails the entries to be written in + the store to trigger creation of a device. The backend domain ID is + taken from the given config, paths for frontend and backend are + computed, and these are added to the backDetails and frontDetails + dictionaries for writing to the store, including references from + frontend to backend and vice versa. + + @return A pair of (backpath, frontpath). backDetails and frontDetails + will have been updated appropriately, also. @param config The configuration of the device, as given to {@link #createDevice}. @@ -298,24 +333,7 @@ class DevController: 'state' : str(xenbusState['Initialising']) }) - log.debug('DevController: writing %s to %s.', str(frontDetails), - frontpath) - log.debug('DevController: writing %s to %s.', str(backDetails), - backpath) - - while True: - t = xstransact() - try: - t.remove2(backpath, HOTPLUG_STATUS_NODE) - - t.write2(frontpath, frontDetails) - t.write2(backpath, backDetails) - - if t.commit(): - return - except: - t.abort() - raise + return (backpath, frontpath) def waitForBackend(self, devid): -- 2.30.2